unit JATUIF_Component_SmallButton;

{$mode objfpc}{$H+}

interface

uses
    Classes, SysUtils, JATUIF_Component, JATUIF_Driver_Screen, JATUIF_Driver_Debug, Video;

type

    { TSmallButton }
    TButton_Colors = record
      Normal_Text : Byte;
      Normal_Background : Byte;
      Highlight_Text : Byte;
      Highlight_Background : Byte;
    end;

    TCoord = record
      X:Integer;
      Y:Integer;
    end;

    TSmallButton = class(TComponent)
      Private
        TopLeft : TCoord;
        BottomRight : TCoord;
        Button_Text : String;
        Colors : TButton_Colors;
        Procedure DrawHighlighted;
        Procedure DrawNormal;
      Protected
        Procedure _OnMouseEnter; override;
        Procedure _OnMouseLeave; override;
        Procedure _OnClick; override;
        Procedure Draw; override;
      Public
        Constructor Create(Parent:TScreen; X1,Y1:Integer; Text:String; TextColor:Byte; Background:Byte; HighlightText:Byte; HightlightBackground:Byte);
    end;

implementation

{ TSmallButton }

constructor TSmallButton.Create(Parent: TScreen; X1, Y1: Integer; Text: String;
            TextColor: Byte; Background: Byte; HighlightText: Byte;
            HightlightBackground: Byte);
begin
     Button_Text:= Text;
     TopLeft.X:= X1;
     TopLeft.Y:= Y1;
     BottomRight.Y:= Y1;
     BottomRight.X:= TopLeft.X+Length(Button_Text)-1;
     Colors.Normal_Text:= TextColor;
     Colors.Normal_Background:= Background;
     Colors.Highlight_Text:= HighlightText;
     Colors.Highlight_Background:= HightlightBackground;
     dbg('SmallButton',IntToStr(Topleft.X)+':'+IntToStr(TopLeft.Y)+'|'+IntToStr(BottomRight.X)+':'+IntToStr(BottomRight.Y));
     inherited Create(Parent, TopLeft.X, TopLeft.Y, BottomRight.X, BottomRight.Y);
end;

procedure TSmallButton.Draw;
Begin
     DrawNormal;
end;

procedure TSmallButton.DrawHighlighted;
begin
     If Length(Button_Text) = 1 then begin
         Screen.DrawCharXY(GetTag,TopLeft.X,TopLeft.Y,Button_Text[1],Colors.Highlight_Text,Colors.Highlight_Background);
     end else begin
         Screen.DrawXY(GetTag,TopLeft.X,TopLeft.Y,Button_Text,Colors.Highlight_Text,Colors.Highlight_Background);
     end;
end;

procedure TSmallButton.DrawNormal;
begin
     If Length(Button_Text) = 1 then begin
        Screen.DrawCharXY(GetTag,TopLeft.X,TopLeft.Y,Button_Text[1],Colors.Normal_Text,Colors.Normal_Background);
     end else begin
         Screen.DrawXY(GetTag,TopLeft.X,TopLeft.Y,Button_Text,Colors.Normal_Text,Colors.Normal_Background);
     end;
end;

procedure TSmallButton._OnMouseEnter;
begin
     DrawHighlighted;
     inherited;
end;

procedure TSmallButton._OnMouseLeave;
begin
     DrawNormal;
     inherited;
end;

procedure TSmallButton._OnClick;
begin
     inherited;
end;

end.

